package com.cloud.pole.shop.controller.goods.admin;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.common.rest.BaseController;
import com.cloud.pole.shop.biz.goods.ShopGoodsBrandBiz;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsBrand;
import com.cloud.pole.shop.service.goods.GoodsBrandService;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/goods/brand/admin")
@Slf4j
public class GoodsBrandAdminController extends BaseController<ShopGoodsBrandBiz,ShopGoodsBrand>{
	
	@Autowired
    private GoodsBrandService goodsBrandService;
	
	/**
	 * 分页品牌
	 * @param pageNo
	 * @param pageSize
	 * @param mobile
	 * @param templateName
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/list")
    @ResponseBody
    public ApiRestResponse<ShopGoodsBrand> list(Integer pageNo, Integer pageSize,String brandName){
		pageNo = (pageNo==null||pageNo<1) ? 1 : pageNo;
		pageSize = (pageSize==null||pageSize<1) ? 10 : pageSize;
		try {
			Map<String, Object> params = new HashMap<>();
			params.put("brandName", brandName);
			PageInfo<ShopGoodsBrand> pageInfo = goodsBrandService.selectPageShopGoodsBrandAdminList(params, pageNo, pageSize);
			return ApiRestResponse.successOfPage("成功", (int)pageInfo.getTotal(), pageInfo.getPages(), pageInfo.getPageSize(),
					pageInfo.getList());
		} catch (Exception e) {
			e.printStackTrace();
			return ApiRestResponse.fail(e.toString(), null);
		}
    }
	
}
